import xadmin
from django.urls import path, include
from VueShop.settings import MEDIA_ROOT
from django.views.static import serve
from django.views.generic import TemplateView
from rest_framework.documentation import include_docs_urls
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.routers import DefaultRouter

from goods import views as good_views
from users import views as user_views
from trade import views as trade_views
from user_operation import views as operation_views

__author__ = '骆杨'


router = DefaultRouter()
# 用户认证API
router.register('code', user_views.SmsCodeViewSet, base_name='code')
# 商品数据API
router.register('goods', good_views.GoodsViewSet, base_name='goods')
# 获取商品分类
router.register('categorys', good_views.CategoryViewSet, base_name='categorys')
# 获取热搜词
router.register('hotsearchs', good_views.HotSearchViewSet, base_name='hotsearchs')
# 获取轮播图
router.register('banners', good_views.BannerViewSet, base_name='banners')
# 首页商品
router.register('indexgoods', good_views.IndexGoodsViewSet, base_name='indexgoods')
# 用户收藏
router.register('userfavs', operation_views.UserFavViewSet, base_name='userfavs')
# 用户留言
router.register('messages', operation_views.LeavingMessageViewSet, base_name='messages')
# 用户地址
router.register('address', operation_views.AddressViewSet, base_name='address')
# 用户信息
router.register('users', user_views.UserViewSet, base_name='users')
# 购物车
router.register('shopcarts', trade_views.ShoppingCartViewSet, base_name='shopcarts')
# 订单
router.register('orders', trade_views.OrderViewSet, base_name='orders')

urlpatterns = [
    # 后台管理
    path('admin/', xadmin.site.urls),
    # 媒体文件
    path('media/<path:path>', serve, {'document_root': MEDIA_ROOT}),
    # DRF登录API
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    # DRF文档API
    path('docs/', include_docs_urls(title='文档')),
    # JWT验证API
    path('login/', obtain_jwt_token),
    # 支付宝接口
    path('alipay/return/', trade_views.AliPayView.as_view(), name='alipay'),
    # 接口路由
    path('', include(router.urls)),
    # 前端页面
    path('index/', TemplateView.as_view(template_name='index.html'), name='index'),
]
